//
//  JHStatusToobar.swift
//  JHSinaWeibo
//
//  Created by apple on 16/6/12.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit
import SnapKit

class JHStatusToobar: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor(white: 0.95,alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置界面
    private func setupUI(){
    addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
     addChildBtn(commenBtn, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(zanBtn, title: "赞", imageName: "timeline_icon_like")
        //子视图平分父视图
        repostBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            
        }
        commenBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.bottom.equalTo(repostBtn)
            make.width.equalTo(repostBtn.snp_width)
            
        }
        zanBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commenBtn.snp_right)
            make.top.bottom.equalTo(commenBtn)
            make.width.equalTo(commenBtn.snp_width)
            make.right.equalTo(self)
        }
        //添加分割线
        let sepView1 = lineView()
        let sepView2 = lineView()
        let width = 1 / UIScreen.mainScreen().scale
        addSubview(sepView1)
        addSubview(sepView2)
        sepView1.snp_makeConstraints { (make) in
            make.left.equalTo(commenBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比 1: 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        sepView2.snp_makeConstraints { (make) in
            make.left.equalTo(commenBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比 1: 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }

    }
    private func lineView() -> UIView{
    let line = UIView()
        //设置颜色
        
    line.backgroundColor = UIColor.purpleColor()
        
    return line
    }

    private func addChildBtn(btn:UIButton,title:String,imageName:String){
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        //设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: ""), forState: .Normal)
        //添加到父视图上
        //自适应大小
        btn.sizeToFit()
        self.addSubview(btn)
    }
    //懒加载控件
    private lazy var repostBtn:UIButton = UIButton()
    private lazy var commenBtn:UIButton = UIButton()
    private lazy var zanBtn:UIButton = UIButton()
}
